package com.sky.controller.admin;

import com.sky.dto.ReportSelectDTO;
import com.sky.result.Result;
import com.sky.service.admin.ReportService;
import com.sky.vo.OrderReportVO;
import com.sky.vo.SalesTop10ReportVO;
import com.sky.vo.TurnoverReportVO;
import com.sky.vo.UserReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;


@Slf4j
@Api(tags = "数据统计相关接口")
@RestController("adminReportController")
@RequestMapping("/admin/report")
public class ReportController {

    @Autowired
    private ReportService reportService;


    /**
     * 用户统计接口
     * @return
     */
    @ApiOperation("用户统计接口")
    @GetMapping("/userStatistics")
    public Result<UserReportVO> userStatistics(ReportSelectDTO reportSelectDTO){
        UserReportVO userStatistics = reportService.userStatistics(reportSelectDTO);
        return Result.success(userStatistics);
    }


    /**
     * 营业额统计接口
     * @param reportSelectDTO
     * @return
     */
    @ApiOperation("营业额统计接口")
    @GetMapping("turnoverStatistics")
    public Result<TurnoverReportVO> turnoverStatistics(ReportSelectDTO reportSelectDTO){
        TurnoverReportVO turnoverReportVO = reportService.turnoverStatistics(reportSelectDTO);
        return Result.success(turnoverReportVO);
    }


    /**
     * 订单统计接口
     * @param reportSelectDTO
     * @return
     */
    @ApiOperation("订单统计接口")
    @GetMapping("/ordersStatistics")
    public Result<OrderReportVO> orderStatistics(ReportSelectDTO reportSelectDTO){
        OrderReportVO orderReportVO = reportService.orderStatistics(reportSelectDTO);
        return Result.success(orderReportVO);
    }

    /**
     * 查询销量排名top10接口
     * @param reportSelectDTO
     * @return
     */
    @ApiOperation("查询销量排名top10接口")
    @GetMapping("/top10")
    public Result<SalesTop10ReportVO> queryTheTopTenSales(ReportSelectDTO reportSelectDTO){
        SalesTop10ReportVO salesTop10ReportVO = reportService.queryTheTopTenSales(reportSelectDTO);
        return Result.success(salesTop10ReportVO);
    }

    /**
     *导出Excel报表相关接口
     * @return
     */
    @ApiOperation("导出Excel报表接口")
    @GetMapping("/export")
    public Result export(HttpServletResponse httpServletResponse)  {
        reportService.export(httpServletResponse);
        return Result.success();
    }
}
